<!-- prettier-ignore -->
<!-- 读取xlsx里面的信息 -->
<template>
  <div>
    <input type="file" accept=".xls,.xlsx" @change="readExcel($event)">
  </div>
</template>

<script>
import * as XLSX from "xlsx";
export default {
  name: "xlsxRead.vue",
  data() {
    return {}
  },
  methods: {
    readExcel(e){
      const file = e.target.files[0]
      const fileReader = new FileReader()
      fileReader.readAsArrayBuffer(file);
      fileReader.onload = ev => {
        try {
          const data = ev.target.result;
          const workbook = XLSX.read(data, {
            type: "binary"
          });
          const wsname = workbook.SheetNames[0]; //取第一张表
          const ws = XLSX.utils.sheet_to_json(workbook.Sheets[wsname]); //生成json表格内容
          console.log(ws);
        } catch (e) {
          console.log(e)
          return false;
        }
      }
      fileReader.onerror = function (e) {
        console.error("文件读取失败:", e.target.error);
      };
    }
  }
}
</script>

<style scoped>

</style>